package com.dong.es.entity.dtocast.base;


import com.dong.es.entity.EsBaseDTO;
import com.dong.es.entity.EsViewDTO;
import com.dong.es.entity.dtocast.DTOCastMethod;
import com.dong.es.entity.searchparam.query.match.EsTermQueryParam;

/**
 * 使用示例：@DTOCastAnno(sort = 10, field = CsmLocDTO.ID, paramFields = {"id"}, method = DTOCastTerm.class)
 * {@code field = CsmLocDTO.ID} 对应 {@link #field}
 * {@code paramFields = {"id"}} 对应 {@link #value}
 *
 * @description: term 参数转换
 * @author: 陈瑞东
 * @create: 2022-06-21 09:56
 */
public class DTOCastTerm extends DTOCastMethod {

    // 字段名
    private String field;
    // 字段值
    private Object value;

    @Override
    protected Integer sizeLimit() {
        return 2;
    }

    @Override
    protected Class[] typeLimit() {
        return new Class[] {String.class, Object.class};
    }

    @Override
    protected void load(Object... args) {
        String field = args[0].toString();
        Object value = args[1];

        this.field = field;
        this.value = value;
    }

    @Override
    protected void doCast(EsViewDTO viewDTO, EsBaseDTO baseDTO) {
        new EsTermQueryParam(field, value).addTo(baseDTO);
    }
}
